# -*- coding: utf-8 -*-

'''
/**
 * @addtogroup az_module2
 * az_module2
 * @{
 */
/**
 * @file        az_module2.py
 * @brief       XXXX
 * @note        XXXX
 * @author      靳普诏(puzhao.jin@hopechart.com)
 * @date        2024/04/18
 * @version     1.0

 * @par         修改日志
 * <table>
 * <tr><th>Date         <th>Version     <th>Author      <th> Description
 * <tr><td>2024/04/18   <td>1.0         <td>靳普诏       <td> 创建初始版本
 * @copyright   xxxx
 */
'''

import sys
import os
import datetime

# 获取当前日期和时间
current_datetime = datetime.datetime.now()
# 格式化输出当前日期和时间
formatted_date = current_datetime.strftime("%Y-%m-%d")
formatted_time = current_datetime.strftime("%H:%M:%S")

# 输出格式化后的日期和时间
print(f"当前日期和时间: {formatted_date} {formatted_time}")

import EasyXlsx
from EasyJinja2 import TEasyJinja2


## 获取当前脚本所在的目录
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
# 输出目录路径
print("SCRIPT_DIR: "+ SCRIPT_DIR)



class TAzModule3:
    def __init__(self, xlsx_name:str, ja2_folder:str):
        self.xlsx_name = xlsx_name
        self.ja2_folder = ja2_folder
        
        self.ja2 = TEasyJinja2(ja2_folder)
        self.gInfo = {}
        self.xRS = []
        self.xCS = []
        self.user = {"gInfo_":self.gInfo, "xRS_":self.xRS, "xCS_":self.xCS}

    def PreAddJaGlobalFuncDict(self, func_dict:dict):
        """
        example:
        def getName(param:str) -> str:
            return "Hello, " + param

        func_dict = {"JF_GetName": getName}
        demo.ja2.AddGlobalFuncDict(func_dict)
        """
        self.ja2.AddGlobalFuncDict(func_dict)

    def _LoadXlsxColumnDictList(self, sheet_name:str) -> list:
        return EasyXlsx.ReadExcelParamListByColumn(self.ja2, sheet_name)

    def _LoadXlsxRowDictList(self, sheet_name:str) -> list:
        return EasyXlsx.ReadExcelParamListByRow(self.ja2, sheet_name)
    
    def LoadGloabalInfos(self, sheet_name:str = "gInfo_"):
        """
        从Excel中读取全局变量，并添加到全局变量字典中
        """
        self.gInfo = self._LoadXlsxColumnDictList(sheet_name)[0]

    def LoadXlsxRowSheet(self, sheet_name:str):
        """
        从Excel中读取行模式参数，并添加到全局变量字典中
        """
        self.xRS = self._LoadXlsxRowDictList(sheet_name)

    def LoadXlsxColumnSheet(self, sheet_name:str):
        """
        从Excel中读取列模式参数，并添加到全局变量字典中
        """
        self.xCS = self._LoadXlsxColumnDictList(sheet_name)


    def Render(self, ja2_template:str, out_filename:str):
        return self.ja2.Render(self.user, ja2_template, out_filename)



